package demo2;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class TestSerializable {
    public static void main(String[] args) throws Exception{
        Student student1 = new Student("李四",22);
        // 序列化
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\student"));
        oos.writeObject(student1);
        System.out.println(student1);
        oos.close();

        // 反序列化
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D:\\student"));
        Student student2 = (Student) ois.readObject();
        System.out.println(student2);
    }
}
